/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tk.eigh.ksvg.types;

import java.io.Serializable;
import java.util.logging.Logger;
import tk.eigh.ksvg.SVGException;

/**
 *
 * @author nt
 */
public class SVGLength implements Serializable {

    protected SVGNumber number;
    protected SVGUnits unit;

    public SVGLength(SVGNumber number, SVGUnits unit) {
        if (number.getValue() < 0) {
            throw new SVGException(getClass().getName().concat(" must not be negative value"));
        }
        this.number = number;
        this.unit = unit;
    }

    public SVGLength(SVGNumber number) {
        if (number.getValue() < 0) {
            throw new SVGException(getClass().getName().concat(" must not be negative value"));
        }
        this.number = number;
    }

    public SVGLength() {
    }

    @Override
    public String toString() {
        try {
            return unit != null ? String.format("%1$s%2$s",number,unit.toString()) : String.format("%s",number);
        } catch (NullPointerException ex) {
            return "inherit";
        }
    }
}
